package com.qiniuyun.backai.controller;

import com.qiniuyun.backai.common.R;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * ASR服务控制器
 * @author: 王程楠
 * @since: 2025-09-26
 */
@RestController
@RequestMapping("/api/asr")
@CrossOrigin(origins = "*") // 允许跨域，生产环境应该限制具体域名
public class AsrController {
    
    /**
     * 获取ASR服务状态
     */
    @GetMapping("/status")
    public R<Map<String, Object>> getStatus() {
        Map<String, Object> response = new HashMap<>();
        response.put("status", "running");
        response.put("message", "ASR服务正常运行");
        response.put("websocket_endpoint", "/asr");
        return R.ok("ASR服务状态获取成功", response);
    }
    
    /**
     * 获取ASR配置信息
     */
    @GetMapping("/config")
    public R<Map<String, Object>> getConfig() {
        Map<String, Object> config = new HashMap<>();
        config.put("sample_rate", 16000);
        config.put("channels", 1);
        config.put("bits", 16);
        config.put("format", "pcm");
        config.put("supported_formats", new String[]{"pcm", "wav"});
        return R.ok("ASR配置信息获取成功", config);
    }
    
    /**
     * 健康检查接口
     */
    @GetMapping("/health")
    public R<Map<String, String>> health() {
        Map<String, String> response = new HashMap<>();
        response.put("status", "healthy");
        response.put("timestamp", String.valueOf(System.currentTimeMillis()));
        return R.ok("健康检查成功", response);
    }
}